home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1986 October / 1986-10.d64 / simple assembler (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  4KB  |  139 lines

  1. 10 h=0:rem if h = 0 then assembly is in decimal
  2. 50 he$="0123456789abcdef":sz=1:zo$="000"
  3. 100 print"[147]   simple   assembler  conventions:"
  4. 110 dimm$(56),ty(56),op(56)
  5. 120 fori=1to56:readm$(i)
  6. 122 rop$=mid$(m$(i),4,1):ty(i)=val(rop$)
  7. 124 op$=right$(m$(i),3):op(i)=val(op$)
  8. 126 m$(i)=left$(m$(i),3)
  9. 140 nexti: print
  10. 150 print"immediate     lda #15
  11. 155 [153]"absolute      lda 1500
  12. 160 print"zero page     lda 15
  13. 165 [153]"accumulator   asl
  14. 170 print"indirect x    lda (15x)
  15. 175 [153]"indirect y    lda (15)y
  16. 177 print"zero page x   lda 15x
  17. 179 [153]"zero page y   ldx 15y
  18. 180 print"absolute x    lda 1500x
  19. 185 [153]"absolute y    lda 1500y
  20. 189 print:print"    enter all numbers in ";
  21. 190 ifh=1 thenprint"hex":goto200
  22. 195 print"decimal"
  23. 200 print:print"please input starting address for ml program":input sa$
  24. 210 ifh=1thenh$=sa$:gosub5000:sa=de:goto220
  25. 215 sa=val(sa$)
  26. 220 ta=sa:print"[147]":rem clear the screen
  27. 230 ifh=1thende=sa:sz=3:gosub4000:printh$;:goto240
  28. 235 printsa" ";
  29. 240 inputmn$:print"[145]"spc(20);:rem go up one line and over 20 spaces
  30. 241 rem add new pseudo-ops here
  31. 242 ifright$(mn$,7)="forward"thenfb=sa
  32. 243 ifright$(mn$,7)="resolve"thenfr=sa-fb:pokefb+1,fr-2:print"  ok":goto230
  33. 244 ifright$(mn$,4)="poke"thenprint"addr,number(dec)";
  34. 245 ifright$(mn$,4)="poke"theninputadr,num:pokeadr,num:goto230
  35. 250 ifmn$="end"thenprint:print"      program is from"ta"to"sa:end
  36. 260 l=len(mn$):l$=left$(mn$,3)
  37. 270 fori=1to56:ifl$=m$(i)then300
  38. 280 nexti
  39. 290 goto850
  40. 300 rem primary opcode categories
  41. 301 ty=ty(i):op=op(i)
  42. 305 iffb=sathentn=0:goto2010
  43. 310 ifty=0thengoto1000
  44. 320 ifty=3thenty=1:ifl=3thenop=op+8:goto1000
  45. 330 r$=right$(mn$,l-4):ifh=1thengosub6000
  46. 340 lr$=left$(r$,1):ll=len(r$):iflr$="#"then480
  47. 350 iflr$="("then520
  48. 360 ifty=8then600
  49. 370 ifty=3thenop=op+8:goto1000
  50. 380 ifright$(r$,1)="x"orright$(r$,1)="y"then630
  51. 390 ifleft$(l$,1)="j"then820
  52. 400 tn=val(r$):iftn>255then430
  53. 410 ifty=1orty=3orty=4orty=5thenop=op+4
  54. 420 goto2000
  55. 430 h%=tn/256:l%=tn-256*h%:ifty=2orty=7thenop=op+8:goto470
  56. 440 ifty=1orty=3orty=4orty=5thenop=op+12:goto470
  57. 450 ifty=6orty=9then470
  58. 460 goto850
  59. 470 goto3000
  60. 480 tn=val(right$(r$,ll-1))
  61. 490 ifty=1thenop=op+8:goto2000
  62. 500 ifty=4orty=5thengoto2000
  63. 510 goto850
  64. 520 ifright$(r$,2)=")y"then540
  65. 530 ifright$(r$,2)="x)"then570
  66. 540 tn=val(mid$(r$,2,ll-3))
  67. 550 ifty=1thenop=op+16:goto2000
  68. 560 goto850
  69. 570 tn=val(mid$(r$,2,ll-3))
  70. 580 ifty=1thengoto2000
  71. 590 goto850
  72. 600 tn=val(r$):tn=tn-sa-2:iftn<-128ortn>127thenprint"too far ";:goto850
  73. 610 iftn<0thentn=tn+256
  74. 620 goto2000
  75. 630 ifright$(r$,2)=")y"then540
  76. 640 ifright$(r$,1)="x"then720
  77. 650 rem *zero y
  78. 660 tn=val(left$(r$,ll-1)):iftn>255then680
  79. 670 ifty=2orty=5then730
  80. 675 ifty=1then760
  81. 680 gosub770:ifty=1thenop=op+24:goto710
  82. 690 ifty=5thenop=op+28:goto710
  83. 700 goto850
  84. 710 goto3000
  85. 720 tn=val(left$(r$,ll-1)):iftn>255thengosub770:goto780
  86. 730 ifty=2thenop=op+16:goto760
  87. 740 ifty=1orty=3orty=5thenop=op+20:goto760
  88. 750 goto850
  89. 760 goto2000
  90. 770 h%=tn/256:l%=tn-256*h%:return
  91. 780 ifty=2thenop=op+24:goto810
  92. 790 ifty=1orty=3orty=5thenop=op+28:goto810
  93. 800 goto850
  94. 810 goto3000
  95. 820 tn=val(r$)
  96. 830 gosub770
  97. 840 goto710
  98. 850 print" error ":goto230
  99. 1000 rem 1 byte instructions
  100. 1010 pokesa,op:sa=sa+1:ifh=1then 1030
  101. 1020 printop:goto230
  102. 1030 de = op:gosub4000:printh$:goto230
  103. 2000 rem 2 byte instructions
  104. 2005 iftn>255thenprint" incorrect argument.":goto230
  105. 2010 pokesa,op:pokesa+1,tn:sa=sa+2:ifh=1then2030
  106. 2020 printop;tn:goto230
  107. 2030 de = op:gosub4000:printh$" ";
  108. 2040 de = tn:gosub4000:printh$:goto230
  109. 3000 rem 3 byte instructions
  110. 3010 pokesa,op:pokesa+1,l%:pokesa+2,h%:sa=sa+3:ifh=1then3030
  111. 3020 printop;l%;h%:goto230
  112. 3030 de = op:gosub4000:printh$" ";
  113. 3040 de = l%:gosub4000:printh$" ";
  114. 3050 de = h%:gosub4000:printh$:goto230
  115. 4000 rem  decimal to hex (de to h$)
  116. 4010 h$="":form=szto0step-1:n%=de/(16^m):de=de-n%*16^m:h$=h$+mid$(he$,n%+1,1)
  117. 4020 next:sz=1:return
  118. 5000 rem  hex to decimal (h$ to de)
  119. 5010 d=0:q=3:form=1to4:forw=0to15:ifmid$(h$,m,1)=mid$(he$,w+1,1)then5030
  120. 5020 nextw
  121. 5030 d1=w*(16^(q)):d=d+d1:q=q-1:nextm:de=int(d):return
  122. 6000 rem accept hex opcode input and translate it to decimal
  123. 6010 ifleft$(r$,1)="#"thenh$="00"+right$(r$,2):gosub5000:r$="#"+str$(de):return
  124. 6020 ls=len(r$):az$=left$(r$,1):za$=mid$(r$,ls,1):ifaz$<>"("then6050
  125. 6030 ifza$="y"thenh$="00"+mid$(r$,2,2):gosub5000:r$="("+str$(de)+")y":return
  126. 6040 ifza$=")"thenh$="00"+mid$(r$,2,2):gosub5000:r$="("+str$(de)+"x)":return
  127. 6050 ifza$="x"orza$="y"then6070
  128. 6060 h$=left$(zo$,4-ls)+r$:gosub5000:r$=str$(de):return
  129. 6070 ifls=5thenh$=left$(r$,4):goto6090
  130. 6080 h$="00"+left$(r$,2)
  131. 6090 gosub5000:r$=str$(de)+za$:return
  132. 20000 dataadc1097,and1033,asl3002,bcc8144,bcs8176,beq8240,bit7036,bmi8048
  133. 20010 databne8208,bpl8016,brk0000,bvc8080,bvs8112,clc0024,cld0216,cli0088
  134. 20020 dataclv0184,cmp1193,cpx4224,cpy4192,dec2198,dex0202,dey0136,eor1065
  135. 20030 datainc2230,inx0232,iny0200,jmp6076,jsr9032,lda1161,ldx5162,ldy5160
  136. 20040 datalsr3066,nop0234,ora1001,pha0072,php0008,pla0104,plp0040,rol3034
  137. 20050 dataror3098,rti0064,rts0096,sbc1225,sec0056,sed0248,sei0120,sta1129
  138. 20060 datastx2134,sty2132,tax0170,tay0168,tsx0186,txa0138,txs0154,tya0152
  139.